package com.serkol.ams.controller.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.serkol.ams.bean.Result;
import com.serkol.ams.entity.Handbook;
import com.serkol.ams.service.HandbookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/handbook")
public class HandBookApiController {


    @Autowired
    private HandbookService handbookService;


    @GetMapping("/findByList")
    @ResponseBody
    public Result findByList() {
        QueryWrapper<Handbook> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByDesc(Handbook::getCreateDate);
        List<Handbook> list = handbookService.list(queryWrapper);
        return Result.ok(list);
    }


    //findById
    @GetMapping("/findById")
    @ResponseBody
    public Result findById(@RequestParam(value = "id", defaultValue = "0")  long id) {
        Handbook byId = handbookService.getById(id);
        return Result.ok(byId);
    }
}
